#include "storeManager.h"
#include "modelSoft.h"
#include <QDir>
#include <QStandardPaths>

storeManager::storeManager(modelSoft* myModelSoft, QObject* parent)
    : myModelSoft(myModelSoft)
{
    historyTree = myModelSoft->m_historyManager->historyTree;
}

storeManager::~storeManager()
{
}


void storeManager::saveToFile(std::string fileName)
{
    if (!isFileEmpty(fileName)) {
        clearFile(fileName);
    }
    //遍历QStandardItemModel*
    for (int row = 0; row < historyTree->rowCount(); row++)
    {
        QStandardItem* operation = historyTree->item(row, 0);
        QString operationType = myModelSoft->m_historyManager->splitText(operation->text(), true);
        int operationId = myModelSoft->m_historyManager->splitText(operation->text(), false).toInt();
        if (operationType == "立方体") {
            int shapeId = operationId;
            //查找对应feature
            auto iter = myModelSoft->m_Features.find(shapeId);
            if (iter == myModelSoft->m_Features.end()) {
                return;
            }
            CubeFeature* feature = (CubeFeature*)iter->second;
            std::ofstream outputdata;
            outputdata.open(fileName, ios::out | ios::app);//把数据存入本地文件,文本文件|追加文件打开文件
            if (!outputdata)
            {
                qDebug() << "save " + fileName + " failure";
            }
            outputdata << feature->getFeatureType() << " " << feature->getShapeId() << " " << feature->getLocation().X() << " " << feature->getLocation().Y() << " " << feature->getLocation().Z() << " "
                << feature->getLength() << " " << feature->getWidth() << " " << feature->getHigh() << endl;
            outputdata.close();
        }
        else if (operationType == "球体") {
            int shapeId = operationId;
            //查找对应feature
            auto iter = myModelSoft->m_Features.find(shapeId);
            if (iter == myModelSoft->m_Features.end()) {
                return;
            }
            SphereFeature* feature = (SphereFeature*)iter->second;
            std::ofstream outputdata;
            outputdata.open(fileName, ios::out | ios::app);//把数据存入本地文件
            if (!outputdata)
            {
                qDebug() << "save " + fileName + " failure";
            }
            outputdata << feature->getFeatureType() << " " << feature->getShapeId() << " " << feature->getLocation().X() << " " << feature->getLocation().Y() << " " << feature->getLocation().Z() << " "
                << feature->getRadius1() << endl;
            outputdata.close();
        }
        else if (operationType == "圆柱体") {
            int shapeId = operationId;
            //查找对应feature
            auto iter = myModelSoft->m_Features.find(shapeId);
            if (iter == myModelSoft->m_Features.end()) {
                return;
            }
            CylinderFeature* feature = (CylinderFeature*)iter->second;
            std::ofstream outputdata;
            outputdata.open(fileName, ios::out | ios::app);//把数据存入本地文件
            if (!outputdata)
            {
                qDebug() << "save " + fileName + " failure";
            }
            outputdata << feature->getFeatureType() << " " << feature->getShapeId() << " " << feature->getLocation().X() << " " << feature->getLocation().Y() << " " << feature->getLocation().Z() << " "
                << feature->getRadius1() << " " << feature->getHigh() << endl;
            outputdata.close();
        }
        else if (operationType == "圆锥") {
            int shapeId = operationId;
            //查找对应feature
            auto iter = myModelSoft->m_Features.find(shapeId);
            if (iter == myModelSoft->m_Features.end()) {
                return;
            }
            ConeFeature* feature = (ConeFeature*)iter->second;
            std::ofstream outputdata;
            outputdata.open(fileName, ios::out | ios::app);//把数据存入本地文件
            if (!outputdata)
            {
                qDebug() << "save " + fileName + " failure";
            }
            outputdata << feature->getFeatureType() << " " << feature->getShapeId() << " " << feature->getLocation().X() << " " << feature->getLocation().Y() << " " << feature->getLocation().Z() << " "
                << feature->getRadius1() << " " << feature->getRadius2() << " " << feature->getHigh() << endl;
            outputdata.close();
        }
        else if (operationType == "圆环体") {
            int shapeId = operationId;
            //查找对应feature
            auto iter = myModelSoft->m_Features.find(shapeId);
            if (iter == myModelSoft->m_Features.end()) {
                return;
            }
            TorusFeature* feature = (TorusFeature*)iter->second;
            std::ofstream outputdata;
            outputdata.open(fileName, ios::out | ios::app);//把数据存入本地文件
            if (!outputdata)
            {
                qDebug() << "save " + fileName + " failure";
            }
            outputdata << feature->getFeatureType() << " " << feature->getShapeId() << " " << feature->getLocation().X() << " " << feature->getLocation().Y() << " " << feature->getLocation().Z() << " "
                << feature->getRadius1() << " " << feature->getRadius2() << endl;
            outputdata.close();
        }
        else if (operationType == "布尔运算") {
            int shapeId = operationId;
            //查找对应feature
            auto iter = myModelSoft->m_Features.find(shapeId);
            if (iter == myModelSoft->m_Features.end()) {
                return;
            }
            BrepFeature* feature = (BrepFeature*)iter->second;
            std::ofstream outputdata;
            outputdata.open(fileName, ios::out | ios::app);//把数据存入本地文件
            if (!outputdata)
            {
                qDebug() << "save " + fileName + " failure";
            }
            outputdata << feature->getFeatureType() << " " << feature->getShapeId() << " " << feature->getTargetFeature()->getShapeId() << " " << feature->getToolFeature()->getShapeId() << " " 
                << feature->getBrepType() << endl;
            outputdata.close();
        }
        else if (operationType == "倒圆角") {
            int shapeId = operationId;
            //查找对应feature
            auto iter = myModelSoft->m_Features.find(shapeId);
            if (iter == myModelSoft->m_Features.end()) {
                return;
            }
            FilletFeature* feature = (FilletFeature*)iter->second;
            std::ofstream outputdata;
            outputdata.open(fileName, ios::out | ios::app);//把数据存入本地文件
            if (!outputdata)
            {
                qDebug() << "save " + fileName + " failure";
            }
            outputdata << feature->getFeatureType() << " " << feature->getShapeId() << " " << feature->getTargetFeature()->getShapeId() << " " 
                << feature->getRadius() << " " << feature->getSubEdgeIndex() << endl;
            outputdata.close();
        }
        else if (operationType == "变换") {
            int shapeId = operationId;
            //查找对应feature
            auto iter = myModelSoft->m_Features.find(shapeId);
            if (iter == myModelSoft->m_Features.end()) {
                return;
            }
            TransformFeature* feature = (TransformFeature*)iter->second;
            std::ofstream outputdata;
            outputdata.open(fileName, ios::out | ios::app);//把数据存入本地文件
            if (!outputdata)
            {
                qDebug() << "save " + fileName + " failure";
            }
            outputdata << feature->getFeatureType() << " " << feature->getShapeId() << " " << feature->getTargetFeature()->getShapeId() << " "
                << feature->getAngel() << " " << feature->getSubEdgeIndex() << " " << feature->getTranslationVec().X() << " " << feature->getTranslationVec().Y() << " " << feature->getTranslationVec().Z() << endl;
            outputdata.close();
        }
        else if (operationType == "拉伸") {
            int shapeId = operationId;
            //查找对应feature
            auto iter = myModelSoft->m_Features.find(shapeId);
            if (iter == myModelSoft->m_Features.end()) {
                return;
            }
            StretchFeature* feature = (StretchFeature*)iter->second;
            std::ofstream outputdata;
            outputdata.open(fileName, ios::out | ios::app);//把数据存入本地文件
            if (!outputdata)
            {
                qDebug() << "save " + fileName + " failure";
            }
            outputdata << feature->getFeatureType() << " " << feature->getShapeId() << " " << feature->getTargetFeature()->getShapeId() << " "
                << feature->getStretchType() << " " << feature->getSubShapeIndex() << " " << feature->getStretchVec().X() << " " << feature->getStretchVec().Y() << " " << feature->getStretchVec().Z() << endl;
            outputdata.close();
        }
        else if (operationType == "旋转体") {
            int shapeId = operationId;
            //查找对应feature
            auto iter = myModelSoft->m_Features.find(shapeId);
            if (iter == myModelSoft->m_Features.end()) {
                return;
            }
            RevolFeature* feature = (RevolFeature*)iter->second;
            std::ofstream outputdata;
            outputdata.open(fileName, ios::out | ios::app);//把数据存入本地文件
            if (!outputdata)
            {
                qDebug() << "save " + fileName + " failure";
            }
            outputdata << feature->getFeatureType() << " " << feature->getShapeId() << " " << feature->getTargetFeature()->getShapeId() << " "
                << feature->getRevolType() << " " << feature->getSubShapeIndex() << " " << feature->getRevolLocation().X() << " " << feature->getRevolLocation().Y() << " " << feature->getRevolLocation().Z() << " " 
                << feature->getRevolDir().X() << " " << feature->getRevolDir().Y() << " " << feature->getRevolDir().Z() << endl;
            outputdata.close();
        }
        else if (operationType == "挖空") {
            int shapeId = operationId;
            //查找对应feature
            auto iter = myModelSoft->m_Features.find(shapeId);
            if (iter == myModelSoft->m_Features.end()) {
                return;
            }
            HollowFeature* feature = (HollowFeature*)iter->second;
            std::ofstream outputdata;
            outputdata.open(fileName, ios::out | ios::app);//把数据存入本地文件
            if (!outputdata)
            {
                qDebug() << "save " + fileName + " failure";
            }
            outputdata << feature->getFeatureType() << " " << feature->getShapeId() << " " << feature->getTargetFeature()->getShapeId() << " "
                << feature->getHollowD() << " " << feature->getHollowTolerance() << " ";
            for (auto i : feature->getSubFaceIndexs())
            {
                outputdata << i << " ";
            }
            outputdata << endl;
            outputdata.close();
        }
    }
    
}

int storeManager::stringToFeature(std::string str)
{
    std::ifstream inputdata;
    inputdata.open(str, ios::in);//系统加载，读入初始化数据
    if (!inputdata)
    {
        cerr << "open data.ini failure" << endl;
        exit(0);
    }
    while (!inputdata.eof())//eof() 检查是否到达文件末尾
    {
        char readStrnum[100];
        char numStr[5];
        int i=0, j=0;
        inputdata.getline(readStrnum, 100);
        while (readStrnum[i] != ' ') numStr[j++] = readStrnum[i++];
        numStr[j] = '\0';
        std::string readStr(readStrnum);
        if (atoi(numStr) == 1) {
            myModelSoft->m_historyManager->redoByFeature(writeIntoCubeFeature(readStr.substr(i,-1)));
        }
        else if (atoi(numStr) == 2) {
            myModelSoft->m_historyManager->redoByFeature(writeIntoConeFeature(readStr.substr(i, -1)));
        }
        else if (atoi(numStr) == 3) {
            myModelSoft->m_historyManager->redoByFeature(writeIntoSphereFeature(readStr.substr(i, -1)));
        }
        else if (atoi(numStr) == 4) {
            myModelSoft->m_historyManager->redoByFeature(writeIntoCylinderFeature(readStr.substr(i, -1)));
        }
        else if (atoi(numStr) == 5) {
            myModelSoft->m_historyManager->redoByFeature(writeIntoTorusFeature(readStr.substr(i, -1)));
        }
        else if (atoi(numStr) == 6) {
            myModelSoft->m_historyManager->redoByFeature(writeIntoBrepFeature(readStr.substr(i, -1)));
        }
        else if (atoi(numStr) == 7) {
            myModelSoft->m_historyManager->redoByFeature(writeIntoFilletFeature(readStr.substr(i, -1)));
        }
        else if (atoi(numStr) == 8) {
            myModelSoft->m_historyManager->redoByFeature(writeIntoTransformFeature(readStr.substr(i, -1)));
        }
        else if (atoi(numStr) == 9) {
            myModelSoft->m_historyManager->redoByFeature(writeIntoStretchFeature(readStr.substr(i, -1)));
        }
        else if (atoi(numStr) == 10) {
            myModelSoft->m_historyManager->redoByFeature(writeIntoRevolFeature(readStr.substr(i, -1)));
        }
        else if (atoi(numStr) == 11) {
            myModelSoft->m_historyManager->redoByFeature(writeIntoHollowFeature(readStr.substr(i, -1)));
        }
    }
    inputdata.close();
	return 0;
}


CubeFeature* storeManager::writeIntoCubeFeature(std::string readStr)
{
    char numStr[10];
    int i = 1;
    int j = 0;
    gp_Pnt location = gp_Pnt();
    CubeFeature* cubeFeature = new CubeFeature();
    //获取shapeId
    j = 0;
    while (readStr[i] != ' ') numStr[j++] = readStr[i++];
    numStr[j] = '\0';
    cubeFeature->setShapeId(atoi(numStr));
    //获取坐标
    i++;
    j = 0;
    while (readStr[i] != ' ') numStr[j++] = readStr[i++];
    numStr[j] = '\0';
    location.SetX(std::stod(numStr));
    i++;
    j = 0;
    while (readStr[i] != ' ') numStr[j++] = readStr[i++];
    numStr[j] = '\0';
    location.SetY(std::stod(numStr)); i++;
    j = 0;
    while (readStr[i] != ' ') numStr[j++] = readStr[i++];
    numStr[j] = '\0';
    location.SetZ(std::stod(numStr));
    cubeFeature->setLocation(location);
    //获取边长属性
    i++;
    j = 0;
    while (readStr[i] != ' ') numStr[j++] = readStr[i++];
    numStr[j] = '\0';
    cubeFeature->setLength(std::stod(numStr));
    i++;
    j = 0;
    while (readStr[i] != ' ') numStr[j++] = readStr[i++];
    numStr[j] = '\0';
    cubeFeature->setWidth(std::stod(numStr));
    i++;
    j = 0;
    while (readStr[i] != ' ' && readStr[i] != '\0') numStr[j++] = readStr[i++];
    numStr[j] = '\0';
    cubeFeature->setHigh(std::stod(numStr));
    return cubeFeature;
}

ConeFeature* storeManager::writeIntoConeFeature(std::string readStr)
{
    char numStr[10];
    int i = 1;
    int j = 0;
    gp_Pnt location = gp_Pnt();
    ConeFeature* coneFeature = new ConeFeature();
    //获取shapeId
    j = 0;
    while (readStr[i] != ' ') numStr[j++] = readStr[i++];
    numStr[j] = '\0';
    coneFeature->setShapeId(atoi(numStr));
    //获取坐标
    i++;
    j = 0;
    while (readStr[i] != ' ') numStr[j++] = readStr[i++];
    numStr[j] = '\0';
    location.SetX(std::stod(numStr));
    i++;
    j = 0;
    while (readStr[i] != ' ') numStr[j++] = readStr[i++];
    numStr[j] = '\0';
    location.SetY(std::stod(numStr)); i++;
    j = 0;
    while (readStr[i] != ' ') numStr[j++] = readStr[i++];
    numStr[j] = '\0';
    location.SetZ(std::stod(numStr));
    coneFeature->setLocation(location);
    //获取边长属性
    i++;
    j = 0;
    while (readStr[i] != ' ') numStr[j++] = readStr[i++];
    numStr[j] = '\0';
    coneFeature->setRadius1(std::stod(numStr));
    i++;
    j = 0;
    while (readStr[i] != ' ') numStr[j++] = readStr[i++];
    numStr[j] = '\0';
    coneFeature->setRadius2(std::stod(numStr));
    i++;
    j = 0;
    while (readStr[i] != ' ' && readStr[i] != '\0') numStr[j++] = readStr[i++];
    numStr[j] = '\0';
    coneFeature->setHigh(std::stod(numStr));
    return coneFeature;
}

CylinderFeature* storeManager::writeIntoCylinderFeature(std::string readStr)
{
    char numStr[10];
    int i = 1;
    int j = 0;
    gp_Pnt location = gp_Pnt();
    CylinderFeature* cylinderFeature = new CylinderFeature();
    //获取shapeId
    j = 0;
    while (readStr[i] != ' ') numStr[j++] = readStr[i++];
    numStr[j] = '\0';
    cylinderFeature->setShapeId(atoi(numStr));
    //获取坐标
    i++;
    j = 0;
    while (readStr[i] != ' ') numStr[j++] = readStr[i++];
    numStr[j] = '\0';
    location.SetX(std::stod(numStr));
    i++;
    j = 0;
    while (readStr[i] != ' ') numStr[j++] = readStr[i++];
    numStr[j] = '\0';
    location.SetY(std::stod(numStr)); i++;
    j = 0;
    while (readStr[i] != ' ') numStr[j++] = readStr[i++];
    numStr[j] = '\0';
    location.SetZ(std::stod(numStr));
    cylinderFeature->setLocation(location);
    //获取边长属性
    i++;
    j = 0;
    while (readStr[i] != ' ') numStr[j++] = readStr[i++];
    numStr[j] = '\0';
    cylinderFeature->setRadius1(std::stod(numStr));
    i++;
    j = 0;
    while (readStr[i] != ' ' && readStr[i] != '\0') numStr[j++] = readStr[i++];
    numStr[j] = '\0';
    cylinderFeature->setHigh(std::stod(numStr));
    return cylinderFeature;
}

SphereFeature* storeManager::writeIntoSphereFeature(std::string readStr)
{
    char numStr[10];
    int i = 1;
    int j = 0;
    gp_Pnt location = gp_Pnt();
    SphereFeature* sphereFeature = new SphereFeature();
    //获取shapeId
    j = 0;
    while (readStr[i] != ' ') numStr[j++] = readStr[i++];
    numStr[j] = '\0';
    sphereFeature->setShapeId(atoi(numStr));
    //获取坐标
    i++;
    j = 0;
    while (readStr[i] != ' ') numStr[j++] = readStr[i++];
    numStr[j] = '\0';
    location.SetX(std::stod(numStr));
    i++;
    j = 0;
    while (readStr[i] != ' ') numStr[j++] = readStr[i++];
    numStr[j] = '\0';
    location.SetY(std::stod(numStr)); i++;
    j = 0;
    while (readStr[i] != ' ') numStr[j++] = readStr[i++];
    numStr[j] = '\0';
    location.SetZ(std::stod(numStr));
    sphereFeature->setLocation(location);
    //获取边长属性
    i++;
    j = 0;
    while (readStr[i] != ' ' && readStr[i] != '\0') numStr[j++] = readStr[i++];
    numStr[j] = '\0';
    sphereFeature->setRadius1(std::stod(numStr));
    return sphereFeature;
}

TorusFeature* storeManager::writeIntoTorusFeature(std::string readStr)
{
    char numStr[10];
    int i = 1;
    int j = 0;
    gp_Pnt location = gp_Pnt();
    TorusFeature* torusFeature = new TorusFeature();
    //获取shapeId
    j = 0;
    while (readStr[i] != ' ') numStr[j++] = readStr[i++];
    numStr[j] = '\0';
    torusFeature->setShapeId(atoi(numStr));
    //获取坐标
    i++;
    j = 0;
    while (readStr[i] != ' ') numStr[j++] = readStr[i++];
    numStr[j] = '\0';
    location.SetX(std::stod(numStr));
    i++;
    j = 0;
    while (readStr[i] != ' ') numStr[j++] = readStr[i++];
    numStr[j] = '\0';
    location.SetY(std::stod(numStr)); i++;
    j = 0;
    while (readStr[i] != ' ') numStr[j++] = readStr[i++];
    numStr[j] = '\0';
    location.SetZ(std::stod(numStr));
    torusFeature->setLocation(location);
    //获取边长属性
    i++;
    j = 0;
    while (readStr[i] != ' ') numStr[j++] = readStr[i++];
    numStr[j] = '\0';
    torusFeature->setRadius1(std::stod(numStr));
    i++;
    j = 0;
    while (readStr[i] != ' ' && readStr[i] != '\0') numStr[j++] = readStr[i++];
    numStr[j] = '\0';
    torusFeature->setRadius2(std::stod(numStr));
    return torusFeature;
}

BrepFeature* storeManager::writeIntoBrepFeature(std::string readStr)
{
    char numStr[10];
    int i = 1;
    int j = 0;
    BrepFeature* brepFeature = new BrepFeature();
    //获取shapeId
    j = 0;
    while (readStr[i] != ' ') numStr[j++] = readStr[i++];
    numStr[j] = '\0';
    brepFeature->setShapeId(atoi(numStr));
    brepFeature->setBrepId(atoi(numStr));
    brepFeature->setResultId(atoi(numStr));
    //查找目标Feature
    i++;
    j = 0;
    while (readStr[i] != ' ') numStr[j++] = readStr[i++];
    numStr[j] = '\0';
    auto iter1 = myModelSoft->m_Features.find(atoi(numStr));
    if (iter1 == myModelSoft->m_Features.end()) {
        exit(0);
    }
    brepFeature->setTargetFeature(iter1->second);
    //查找ToolFeature
    i++;
    j = 0;
    while (readStr[i] != ' ') numStr[j++] = readStr[i++];
    numStr[j] = '\0';
    auto iter2 = myModelSoft->m_Features.find(atoi(numStr));
    if (iter2 == myModelSoft->m_Features.end()) {
        exit(0);
    }
    brepFeature->setToolFeature(iter2->second);
    //获取布尔运算类型
    i++;
    j = 0;
    while (readStr[i] != ' ' && readStr[i] != '\0') numStr[j++] = readStr[i++];
    numStr[j] = '\0';
    brepFeature->setBrepType(atoi(numStr));
    myModelSoft->m_Features.insert(std::pair<Standard_Integer, BaseFeature*>(brepFeature->getShapeId(), brepFeature));
    return brepFeature;
}

FilletFeature* storeManager::writeIntoFilletFeature(std::string readStr)
{
    char numStr[10];
    int i = 1;
    int j = 0;
    FilletFeature* filletFeature = new FilletFeature();
    //获取shapeId
    j = 0;
    while (readStr[i] != ' ') numStr[j++] = readStr[i++];
    numStr[j] = '\0';
    filletFeature->setShapeId(atoi(numStr));
    filletFeature->setFilletId(atoi(numStr));
    filletFeature->setResultId(atoi(numStr));
    //查找目标Feature
    i++;
    j = 0;
    while (readStr[i] != ' ') numStr[j++] = readStr[i++];
    numStr[j] = '\0';
    auto iter1 = myModelSoft->m_Features.find(atoi(numStr));
    if (iter1 == myModelSoft->m_Features.end()) {
        exit(0);
    }
    filletFeature->setTargetFeature(iter1->second);
    //查找radius
    i++;
    j = 0;
    while (readStr[i] != ' ') numStr[j++] = readStr[i++];
    numStr[j] = '\0';
    filletFeature->setRadius(std::stod(numStr));
    //获取选取子边索引
    i++;
    j = 0;
    while (readStr[i] != ' ' && readStr[i] != '\0') numStr[j++] = readStr[i++];
    numStr[j] = '\0';
    filletFeature->setSubEdgeIndex(atoi(numStr));
    myModelSoft->m_Features.insert(std::pair<Standard_Integer, BaseFeature*>(filletFeature->getShapeId(), filletFeature));
    return filletFeature;
}

TransformFeature* storeManager::writeIntoTransformFeature(std::string readStr)
{
    char numStr[10];
    int i = 1;
    int j = 0;
    gp_Vec location = gp_Vec();
    TransformFeature* transformFeature = new TransformFeature();
    //获取shapeId
    j = 0;
    while (readStr[i] != ' ') numStr[j++] = readStr[i++];
    numStr[j] = '\0';
    transformFeature->setShapeId(atoi(numStr));
    transformFeature->setTransformId(atoi(numStr));
    transformFeature->setResultId(atoi(numStr));
    //查找目标Feature
    i++;
    j = 0;
    while (readStr[i] != ' ') numStr[j++] = readStr[i++];
    numStr[j] = '\0';
    auto iter1 = myModelSoft->m_Features.find(atoi(numStr));
    if (iter1 == myModelSoft->m_Features.end()) {
        exit(0);
    }
    transformFeature->setTargetFeature(iter1->second);
    //查找angel
    i++;
    j = 0;
    while (readStr[i] != ' ') numStr[j++] = readStr[i++];
    numStr[j] = '\0';
    transformFeature->setAngel(std::stod(numStr));
    //获取选取子边索引
    i++;
    j = 0;
    while (readStr[i] != ' ') numStr[j++] = readStr[i++];
    numStr[j] = '\0';
    transformFeature->setSubEdgeIndex(atoi(numStr));
    //获取坐标
    i++;
    j = 0;
    while (readStr[i] != ' ') numStr[j++] = readStr[i++];
    numStr[j] = '\0';
    location.SetX(std::stod(numStr));
    i++;
    j = 0;
    while (readStr[i] != ' ') numStr[j++] = readStr[i++];
    numStr[j] = '\0';
    location.SetY(std::stod(numStr)); i++;
    j = 0;
    while (readStr[i] != ' ' && readStr[i] != '\0') numStr[j++] = readStr[i++];
    numStr[j] = '\0';
    location.SetZ(std::stod(numStr));
    transformFeature->setTranslationVec(location);
    myModelSoft->m_Features.insert(std::pair<Standard_Integer, BaseFeature*>(transformFeature->getShapeId(), transformFeature));
    return transformFeature;
}

StretchFeature* storeManager::writeIntoStretchFeature(std::string readStr)
{
    char numStr[10];
    int i = 1;
    int j = 0;
    gp_Vec location = gp_Vec();
    StretchFeature* stretchFeature = new StretchFeature();
    //获取shapeId
    j = 0;
    while (readStr[i] != ' ') numStr[j++] = readStr[i++];
    numStr[j] = '\0';
    stretchFeature->setShapeId(atoi(numStr));
    stretchFeature->setStretchId(atoi(numStr));
    stretchFeature->setResultId(atoi(numStr));
    //查找目标Feature
    i++;
    j = 0;
    while (readStr[i] != ' ') numStr[j++] = readStr[i++];
    numStr[j] = '\0';
    auto iter1 = myModelSoft->m_Features.find(atoi(numStr));
    if (iter1 == myModelSoft->m_Features.end()) {
        exit(0);
    }
    stretchFeature->setTargetFeature(iter1->second);
    //查找stretchType
    i++;
    j = 0;
    while (readStr[i] != ' ') numStr[j++] = readStr[i++];
    numStr[j] = '\0';
    stretchFeature->setStretchType(std::stod(numStr));
    //获取选取子边索引
    i++;
    j = 0;
    while (readStr[i] != ' ') numStr[j++] = readStr[i++];
    numStr[j] = '\0';
    stretchFeature->setSubShapeIndex(atoi(numStr));
    //获取坐标
    i++;
    j = 0;
    while (readStr[i] != ' ') numStr[j++] = readStr[i++];
    numStr[j] = '\0';
    location.SetX(std::stod(numStr));
    i++;
    j = 0;
    while (readStr[i] != ' ') numStr[j++] = readStr[i++];
    numStr[j] = '\0';
    location.SetY(std::stod(numStr)); i++;
    j = 0;
    while (readStr[i] != ' ' && readStr[i] != '\0') numStr[j++] = readStr[i++];
    numStr[j] = '\0';
    location.SetZ(std::stod(numStr));
    stretchFeature->setStretchVec(location);
    myModelSoft->m_Features.insert(std::pair<Standard_Integer, BaseFeature*>(stretchFeature->getShapeId(), stretchFeature));
    return stretchFeature;
}

RevolFeature* storeManager::writeIntoRevolFeature(std::string readStr)
{
    char numStr[10];
    int i = 1;
    int j = 0;
    gp_Pnt location = gp_Pnt();
    gp_Dir dir = gp_Dir();
    RevolFeature* revolFeature = new RevolFeature();
    //获取shapeId
    j = 0;
    while (readStr[i] != ' ') numStr[j++] = readStr[i++];
    numStr[j] = '\0';
    revolFeature->setShapeId(atoi(numStr));
    revolFeature->setRevolId(atoi(numStr));
    revolFeature->setResultId(atoi(numStr));
    //查找目标Feature
    i++;
    j = 0;
    while (readStr[i] != ' ') numStr[j++] = readStr[i++];
    numStr[j] = '\0';
    auto iter1 = myModelSoft->m_Features.find(atoi(numStr));
    if (iter1 == myModelSoft->m_Features.end()) {
        exit(0);
    }
    revolFeature->setTargetFeature(iter1->second);
    //查找RevolType
    i++;
    j = 0;
    while (readStr[i] != ' ') numStr[j++] = readStr[i++];
    numStr[j] = '\0';
    revolFeature->setRevolType(std::stod(numStr));
    //获取选取子边索引
    i++;
    j = 0;
    while (readStr[i] != ' ') numStr[j++] = readStr[i++];
    numStr[j] = '\0';
    revolFeature->setSubShapeIndex(atoi(numStr));
    //获取坐标
    i++;
    j = 0;
    while (readStr[i] != ' ') numStr[j++] = readStr[i++];
    numStr[j] = '\0';
    location.SetX(std::stod(numStr));
    i++;
    j = 0;
    while (readStr[i] != ' ') numStr[j++] = readStr[i++];
    numStr[j] = '\0';
    location.SetY(std::stod(numStr)); i++;
    j = 0;
    while (readStr[i] != ' ' && readStr[i] != '\0') numStr[j++] = readStr[i++];
    numStr[j] = '\0';
    location.SetZ(std::stod(numStr));
    revolFeature->setRevolLocation(location);
    //获取坐标
    i++;
    j = 0;
    while (readStr[i] != ' ') numStr[j++] = readStr[i++];
    numStr[j] = '\0';
    dir.SetX(std::stod(numStr));
    i++;
    j = 0;
    while (readStr[i] != ' ') numStr[j++] = readStr[i++];
    numStr[j] = '\0';
    dir.SetY(std::stod(numStr)); i++;
    j = 0;
    while (readStr[i] != ' ' && readStr[i] != '\0') numStr[j++] = readStr[i++];
    numStr[j] = '\0';
    dir.SetZ(std::stod(numStr));
    revolFeature->setRevolDir(dir);
    myModelSoft->m_Features.insert(std::pair<Standard_Integer, BaseFeature*>(revolFeature->getShapeId(), revolFeature));
    return revolFeature;
}

HollowFeature* storeManager::writeIntoHollowFeature(std::string readStr)
{
    char numStr[10];
    int i = 1;
    int j = 0;
    HollowFeature* hollowFeature = new HollowFeature();
    //获取shapeId
    j = 0;
    while (readStr[i] != ' ') numStr[j++] = readStr[i++];
    numStr[j] = '\0';
    hollowFeature->setShapeId(atoi(numStr));
    hollowFeature->setHollowId(atoi(numStr));
    hollowFeature->setResultId(atoi(numStr));
    //查找目标Feature
    i++;
    j = 0;
    while (readStr[i] != ' ') numStr[j++] = readStr[i++];
    numStr[j] = '\0';
    auto iter1 = myModelSoft->m_Features.find(atoi(numStr));
    if (iter1 == myModelSoft->m_Features.end()) {
        exit(0);
    }
    hollowFeature->setTargetFeature(iter1->second);
    //查找HollowD
    i++;
    j = 0;
    while (readStr[i] != ' ') numStr[j++] = readStr[i++];
    numStr[j] = '\0';
    hollowFeature->setHollowD(std::stod(numStr));
    //获取HollowTolerance
    i++;
    j = 0;
    while (readStr[i] != ' ') numStr[j++] = readStr[i++];
    numStr[j] = '\0';
    hollowFeature->setHollowTolerance(atoi(numStr));
    i++;
    //获取挖空对象删除面list
    while (readStr[i+1] != '\0') {
        j = 0;
        while (readStr[i] != ' ') numStr[j++] = readStr[i++];
        numStr[j] = '\0';
        hollowFeature->addSubShapeIndex(atoi(numStr));
    }
    myModelSoft->m_Features.insert(std::pair<Standard_Integer, BaseFeature*>(hollowFeature->getShapeId(), hollowFeature));
    return hollowFeature;
}
